The addition of programmable vertex shaders and pixel shaders makes visual quality in real-time graphics take a leap towards cinematic realism. Thanks to the programmable graphics processors on newer graphics cards, developers can add personalized combinations of graphics operations by using these shaders, creating their own effects to their games and other applications. A shader is a piece of code written in a shading language that is designed to be used in either a programmable vertex pipeline or a programmable pixel pipeline within a programmable graphics processor.
Vertex shaders play an important role in allowing developers to create realistic environments and characters that were once beyond the scope of available consumer technology. A vertex typically represents a corner of a polygon where edges meet. Thus, each triangle has three vertices. Likewise, objects in a 3D scene are typically created using triangles. Vertex shaders allow developers to designate the values of the vertex data, so that a vertex emerges with a different color, different textures, or a different position in space. More particularly, a vertex shader is a graphics processing function which manipulates vertex data values typically in 3D space through mathematical operations on an object. These variations range anywhere from differences in color, texture coordinates, orientations in space, fog (how dense it may appear at a certain elevation), and point size. When a vertex shader is enabled, it replaces the fixed-function pipeline for vertices. The shader does not operate on a primitive like a triangle, but on a single vertex. A vertex shader cannot create or destroy vertices, it can only manipulate the vertices. For every vertex to be processed, the shader program executes.
In order for a vertex shader to execute, it needs to know what its inputs are. The inputs are vertices, but there is no fixed definition of what a “vertex” looks like. Typically the input to a vertex shader is a vertex containing a 3D position (X, Y, Z), sometimes having an associated color (r, g, b, a) or texture coordinate (u, v), or other types of data. Furthermore, the data type for each of these elements in the input to a vertex shader could be different (i.e., a single float or 4 floats or 4 unsigned bytes, etc.).
While the data layout and composition of the inputs to a vertex shader need to be flexible to accommodate the author/programmer's needs, vertex shader hardware can only read the inputs in a fixed manner. There are a designated set of input registers that are expected to be filled with the incoming vertex data in some fashion so that the program code in the vertex shader can read the input registers, perform whatever algorithms the vertex shader is programmed to do, and emit an output vertex to output registers. A problem is how to describe to the graphics hardware where to fetch vertex data from, how to interpret the data, and where to arrange it in vertex shader input registers so that the vertex shader may execute.
A pixel shader is a small program which processes pixels and executes on the graphics processor. Put another way, a pixel shader is a graphics function that calculates effects on a per-pixel basis. With pixel shaders, developers can render, light, shade, and color in excess of 2 million pixels per frame all the while keeping a steady 60 frames per second. Programmable pixel shaders take this further by allowing developers to create their own per-pixel effects. In turn, this allows developers control for determining the lighting, shading, and color of each individual pixel, allowing them to create a myriad of unique surface effects. When a pixel shader has been created, a fragment processing function has been created which manipulates fragment data. The 3D scene in OpenGL (a 3D graphics language), for example, is projected onto the XY-plane where the points are called fragments. The fragments contain information such as position and texture coordinates. Several fragments can be added together when displayed to a pixel on the screen.
Microsoft® DirectX® is a suite of multimedia APIs built into Microsoft Windows® operating systems. It provides a standard platform that enables software developers to access specialized hardware features without having to write hardware-specific code. Currently, in high level shading languages for a graphics API, such as Microsoft® DirectX® 8, variables referenced in shader code are tied to specific streams of vertex data. However, modifying the shader code, which requires managing the correct register references, may be complicated to a novice user. Microsoft® Direct® 9.0 contains a high-level shader language for developing and debugging shaders in a C-like language. This capability is in addition to the assembly language shader capability that is used to generate vertex shaders, pixel shaders, and effects. Microsoft® Direct3D® 9 introduced a way to decouple the declaration from the vertex stream data to a particular register; however, this is currently not flexible enough either.
Developers program shaders in assembly and high level languages with variables that refer to registers. Thus, the registers are coupled to the language. Therefore, to modify and enhance high level language shaders, a developer must manually manipulate the registers. Moreover, conventional shaders cannot be reused, as they are only capable of operating on a particular set of mesh data.
In view of the foregoing, there is a need for systems and methods that overcome the limitations and drawbacks of the prior art.